import { _decorator, Component, Label, Node } from 'cc';
import { AudioMgr, SoundName } from '../Mgr/AudioMgr';
import { UIMgr } from '../Mgr/UIMgr';
import { AssetList, Global } from '../Global';
import { LocalStorageMgr } from '../Mgr/LocalStorageMgr';
const { ccclass, property } = _decorator;

@ccclass('GameSet')
/**
 * 游戏设置层
 */
export class GameSet extends Component {

    //音乐关闭按钮
    @property(Node)
    private MusicClose: Node = null;

    //音效关闭按钮
    @property(Node)
    private SoundClose: Node = null;

    //震动关闭按钮
    @property(Node)
    private ShakeClose: Node = null;

    //放弃按钮
    @property(Node)
    private GiveUpButton: Node = null;

    //关闭按钮
    @property(Node)
    private CloseButton: Node = null;

    /**
     * 初始化
     */
    public Init(_islogin: boolean) {
        // this.MuteButton.active = !AudioMgr.instance.IsBgPlay;

        this.MusicClose.active = !AudioMgr.instance.IsBgPlay;
        this.SoundClose.active = !AudioMgr.instance.IsEffectPlay;
        this.ShakeClose.active = !AudioMgr.instance.IsShakePlay;
        this.GiveUpButton.active = false;

        this.GiveUpButton.active = !_islogin;
        this.CloseButton.active = _islogin;

    }

    /**
     * 点击主页按钮
     */
    private HomeClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        UIMgr.Instance.HidePop(AssetList.Pop.GAMESET);
        UIMgr.Instance.UdpateScene(AssetList.Scene.LoginScene);
    }

    /**
     * 点击音效按钮
     */
    private MusicClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);

        AudioMgr.instance.IsBgPlay = !AudioMgr.instance.IsBgPlay;
        this.MusicClose.active = !AudioMgr.instance.IsBgPlay;

        if (AudioMgr.instance.IsBgPlay) {
            AudioMgr.instance.PlayBgSound(SoundName.Bg);
        } else {
            AudioMgr.instance.StopBgSound();
        }
    }

    /**
     * 点击音效按钮
     */
    private SoundClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        AudioMgr.instance.IsEffectPlay = !AudioMgr.instance.IsEffectPlay;
        this.SoundClose.active = !AudioMgr.instance.IsEffectPlay;
    }

    /**
     * 点击震动按钮
     */
    private ShakeClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        AudioMgr.instance.IsShakePlay = !AudioMgr.instance.IsShakePlay;
        this.ShakeClose.active = !AudioMgr.instance.IsShakePlay;
    }

    /**
     * 点击关闭
     */
    private CloseClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        Global.IsEnd = false;
        UIMgr.Instance.HidePop(AssetList.Pop.GAMESET);
    }

    /**
     * 点击放弃按钮
     */
    private GiveupClick() {
        AudioMgr.instance.PlayEffect(SoundName.Click);
        UIMgr.Instance.HidePop(AssetList.Pop.GAMESET);
        UIMgr.Instance.UdpateScene(AssetList.Scene.LoginScene);
    }
}


